Kotlin

Ranges and Progressions

Swift
                  if (i in 1..4) {  // equivalent of 1 <= i && i <= 4
    print(i)
}
                
                    if (i in 1..4) {  // equivalent of 1 <= i && i <= 4
    print(i)
}
                  
                  for (i in 1..4) print(i)
                
                    for (i in 1..4) print(i)
                  
                  for (i in 4 downTo 1) print(i)
                
                    for (i in 4 downTo 1) print(i)
                  
                  for (i in 1..8 step 2) print(i)
println()
for (i in 8 downTo 1 step 2) print(i)
                
                    for (i in 1..8 step 2) print(i)
print()
for (i in 8 downTo 1 step 2) print(i)
                  
                  for (i in 1 until 10) {       // i in [1, 10), 10 is excluded
    print(i)
}
                
                    for (i in 1 until 10) {       // i in [1, 10), 10 is excluded
    print(i)
}
                  

Range

                  val versionRange = Version(1, 11)..Version(1, 30)
println(Version(0, 9) in versionRange)
println(Version(1, 20) in versionRange)
                
                    let versionRange = Version(1, 11)..Version(1, 30)
print(Version(0, 9) in versionRange)
print(Version(1, 20) in versionRange)
                  

Progression

                  for (int i = first; i <= last; i += step) {
  // ...
}
                
                    for (int i = first; i <= last; i += step) {
  // ...
}
                  
                  for (i in 1..10) print(i)
                
                    for (i in 1..10) print(i)
                  
                  for (i in 1..8 step 2) print(i)
                
                    for (i in 1..8 step 2) print(i)
                  
                  for (i in 1..9 step 3) print(i) // the last element is 7
                
                    for (i in 1..9 step 3) print(i) // the last element is 7
                  
                  for (i in 4 downTo 1) print(i)
                
                    for (i in 4 downTo 1) print(i)
                  
                  println((1..10).filter { it % 2 == 0 })
                
                    print((1..10).filter { $0 % 2 == 0 })